/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Preguntas.java
 *
 * Created on 05-jun-2012, 12:36:57
 */

package com.cmf.vista;

import com.cmf.controladores.Funciones;
import com.cmf.model.Jugador;
import com.cmf.model.Pregunta;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.StringTokenizer;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.Timer;
import javax.swing.border.MatteBorder;

/**
 *
 * @author jairo jose
 */
public class Preguntas extends javax.swing.JFrame {

    private EscaleraClaret frame;
    private JPanel panel;
    private String respuesta;
    private ButtonGroup botones;
    private Timer t;
    private int temp,segundero;

    /** Creates new form Preguntas */
 
    //construtor principal de la logica del juego
    public Preguntas(EscaleraClaret frame, JPanel panel, Pregunta p, int temp) {
        
        this.temp=temp*1000;
        segundero=temp;
        respuesta=p.getRepuestaCorrecta();
        panel.setBorder(new MatteBorder(3, 3, 3, 3, Color.MAGENTA));
        Component[] components = panel.getComponents();
        JLabel label=(JLabel) components[0];
        this.frame=frame;
        this.panel=panel;
        frame.enable(false);
        initComponents();
        seg.setText(""+segundero);
        botones=new ButtonGroup();
        botones.add(a);
        botones.add(b);
        botones.add(c);
        botones.add(d);
        jLabel1.setText(label.getText());
        StringTokenizer st=new StringTokenizer(p.getPregunta());
        int token=st.countTokens();
        String[] cad=p.getPregunta().split("\\s");
        String texto=null;
        String texto2="";
        for(int i=0;i<cad.length;i++){

                if(i==0){
                    texto=cad[i];
                }else
                if(i>0&&i<15){
                    texto=texto+" "+cad[i];
                }
                else
                 if(token>15&&i>=15){
                        texto2=texto2+" "+cad[i];

                    }

        }
        pregunta.setText(texto);
        pregunta2.setText(texto2);
        int correcta=new Funciones().azar(4);
        if(correcta==1){
            a.setText(p.getRepuestaCorrecta());
            b.setText(p.getFalsa1());
            c.setText(p.getFalsa2());
            d.setText(p.getFalsa3());
        }else
            if(correcta==2){
                b.setText(p.getRepuestaCorrecta());
                a.setText(p.getFalsa1());
                c.setText(p.getFalsa2());
                d.setText(p.getFalsa3());
            }else
                if(correcta==3){
                    c.setText(p.getRepuestaCorrecta());
                    b.setText(p.getFalsa1());
                    a.setText(p.getFalsa2());
                    d.setText(p.getFalsa3());
                }else
                    if(correcta==4){
                        d.setText(p.getRepuestaCorrecta());
                        b.setText(p.getFalsa1());
                        c.setText(p.getFalsa2());
                        a.setText(p.getFalsa3());
                    }
        
        ImageIcon imagen=new ImageIcon(getClass().getResource("/com/cmf/recursos/imagenes/claret.JPG"));
        setIconImage(imagen.getImage());
        iniciartemporizador();
        t.start();
        dispose();
        setDefaultCloseOperation(0);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        fondo = new javax.swing.JPanel();
        d = new javax.swing.JRadioButton();
        jLabel5 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        c = new javax.swing.JRadioButton();
        jLabel3 = new javax.swing.JLabel();
        b = new javax.swing.JRadioButton();
        jLabel2 = new javax.swing.JLabel();
        a = new javax.swing.JRadioButton();
        seg = new javax.swing.JLabel();
        pregunta2 = new javax.swing.JLabel();
        pregunta = new javax.swing.JLabel();
        responder = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setUndecorated(true);

        fondo.setBackground(new java.awt.Color(0, 0, 255));

        d.setBackground(new java.awt.Color(0, 0, 255));
        d.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        d.setForeground(new java.awt.Color(255, 255, 255));
        d.setText("jRadioButton1");
        d.setFocusable(false);

        jLabel5.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(255, 255, 255));
        jLabel5.setText("4");

        jLabel4.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("3");

        c.setBackground(new java.awt.Color(0, 0, 255));
        c.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        c.setForeground(new java.awt.Color(255, 255, 255));
        c.setText("jRadioButton1");
        c.setFocusable(false);

        jLabel3.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("2");

        b.setBackground(new java.awt.Color(0, 0, 255));
        b.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        b.setForeground(new java.awt.Color(255, 255, 255));
        b.setText("jRadioButton2");
        b.setFocusable(false);

        jLabel2.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("1");

        a.setBackground(new java.awt.Color(0, 0, 255));
        a.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        a.setForeground(new java.awt.Color(255, 255, 255));
        a.setText("jRadioButton1");
        a.setFocusable(false);

        seg.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N
        seg.setForeground(new java.awt.Color(255, 102, 0));
        seg.setText("jLabel2");

        pregunta2.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
        pregunta2.setForeground(new java.awt.Color(255, 255, 255));
        pregunta2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        pregunta2.setText("jLabel2");

        pregunta.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
        pregunta.setForeground(new java.awt.Color(255, 255, 255));
        pregunta.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        pregunta.setText("jLabel2");

        responder.setText("Responder");
        responder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                responderActionPerformed(evt);
            }
        });
        responder.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                responderKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                responderKeyReleased(evt);
            }
        });

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/cmf/recursos/imagenes/pregunta.png"))); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 89)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 51));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("66");

        javax.swing.GroupLayout fondoLayout = new javax.swing.GroupLayout(fondo);
        fondo.setLayout(fondoLayout);
        fondoLayout.setHorizontalGroup(
            fondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(fondoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(fondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pregunta2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(fondoLayout.createSequentialGroup()
                        .addGroup(fondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(fondoLayout.createSequentialGroup()
                                .addGroup(fondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel5))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(fondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(d, javax.swing.GroupLayout.PREFERRED_SIZE, 586, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(c, javax.swing.GroupLayout.PREFERRED_SIZE, 586, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(b, javax.swing.GroupLayout.PREFERRED_SIZE, 586, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(fondoLayout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(a, javax.swing.GroupLayout.PREFERRED_SIZE, 586, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(99, 99, 99)
                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 91, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, fondoLayout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(responder, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(45, 45, 45)
                        .addComponent(seg, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(fondoLayout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addComponent(pregunta, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        fondoLayout.setVerticalGroup(
            fondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, fondoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pregunta, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(pregunta2, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66, Short.MAX_VALUE)
                .addGroup(fondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(fondoLayout.createSequentialGroup()
                        .addGroup(fondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(a)
                            .addComponent(jLabel2))
                        .addGap(18, 18, 18)
                        .addGroup(fondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(b)
                            .addComponent(jLabel3))
                        .addGap(18, 18, 18)
                        .addGroup(fondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(c)
                            .addComponent(jLabel4))
                        .addGap(18, 18, 18)
                        .addGroup(fondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(d, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(fondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(seg, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(fondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(responder, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(30, 30, 30))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(fondo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(fondo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-947)/2, (screenSize.height-459)/2, 947, 459);
    }// </editor-fold>//GEN-END:initComponents

    private void responderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_responderActionPerformed
        // TODO add your handling code here:
        if(a.isSelected()|| b.isSelected() ||c.isSelected() || d.isSelected()){
            dispose();
            ajustarmMarcadores();
            frame.enable(true);
            frame.setVisible(true);
            panel.setBorder(new MatteBorder(3, 3, 3, 3, new Color(255, 0, WIDTH)));
            panel.setOpaque(false);
            panel.setBackground(new Color(239, 239, 239));
            JLabel label=(JLabel) panel.getComponent(0);
            label.setForeground(Color.WHITE);
            t.stop();
            
        }
    }//GEN-LAST:event_responderActionPerformed

    private void responderKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_responderKeyReleased
        // TODO add your handling code here:
        if(evt.getKeyText(evt.getKeyCode()).toUpperCase().equals("A")||evt.getKeyCode()==KeyEvent.VK_1||evt.getKeyCode()==KeyEvent.VK_NUMPAD1)
            a.setSelected(true);
        else
            if(evt.getKeyText(evt.getKeyCode()).toUpperCase().equals("B")||evt.getKeyCode()==KeyEvent.VK_2||evt.getKeyCode()==KeyEvent.VK_NUMPAD2)
                b.setSelected(true);
            else
                if(evt.getKeyText(evt.getKeyCode()).toUpperCase().equals("C")||evt.getKeyCode()==KeyEvent.VK_3||evt.getKeyCode()==KeyEvent.VK_NUMPAD3)
                    c.setSelected(true);
                else
                    if(evt.getKeyText(evt.getKeyCode()).toUpperCase().equals("D")||evt.getKeyCode()==KeyEvent.VK_4||evt.getKeyCode()==KeyEvent.VK_NUMPAD4)
                        d.setSelected(true);
                
    }//GEN-LAST:event_responderKeyReleased

    private void responderKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_responderKeyPressed
        // TODO add your handling code here:
        if(evt.getKeyCode()==KeyEvent.VK_ENTER){
            responderActionPerformed(null);
        }
    }//GEN-LAST:event_responderKeyPressed

    /**
    * @param args the command line arguments
    */
    /*public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Preguntas(this).setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton a;
    private javax.swing.JRadioButton b;
    private javax.swing.JRadioButton c;
    private javax.swing.JRadioButton d;
    private javax.swing.JPanel fondo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel pregunta;
    private javax.swing.JLabel pregunta2;
    private javax.swing.JButton responder;
    private javax.swing.JLabel seg;
    // End of variables declaration//GEN-END:variables

    private void ajustarmMarcadores() {
        t.stop();
        if(a.isSelected()){
            if(a.getText().equals(respuesta)){
                Jugador j[]=frame.getJugador();
                for(int i=0;i<j.length;i++){
                    if(j[i].isTurno()){
                        j[i].setPuntaje(j[i].getPuntaje()+1);
                        if(j.length==4){
                            if(i==0)
                                frame.getJp1().setText(String.valueOf(j[i].getPuntaje()));
                            else
                                if(i==1)
                                    frame.getJp2().setText(String.valueOf(j[i].getPuntaje()));
                                else
                                    if(i==2)
                                        frame.getJp3().setText(String.valueOf(j[i].getPuntaje()));
                                    else
                                        if(i==3)
                                            frame.getJp4().setText(String.valueOf(j[i].getPuntaje()));
                        }else
                            if(j.length==3){
                                if(i==0)
                                    frame.getJp1().setText(String.valueOf(j[i].getPuntaje()));
                                else
                                    if(i==1)
                                        frame.getJp2().setText(String.valueOf(j[i].getPuntaje()));
                                    else
                                        if(i==2)
                                            frame.getJp3().setText(String.valueOf(j[i].getPuntaje()));
                            }else
                                if(j.length==2){
                                    if(i==0)
                                        frame.getJp1().setText(String.valueOf(j[i].getPuntaje()));
                                    else
                                        if(i==1)
                                            frame.getJp2().setText(String.valueOf(j[i].getPuntaje()));
                                }else
                                    if(j.length==1){
                                        if(i==0)
                                            frame.getJp1().setText(String.valueOf(j[i].getPuntaje()));

                                    }
                    }
                }
                frame.setVisible(true);JOptionPane.showMessageDialog(null, "...:::RESPUESTA CORRECTA:::...");
            }else{
                Jugador j[]=frame.getJugador();
                    for(int i=0;i<j.length;i++){
                        if(j[i].isTurno()){
                            j[i].setPuesto(j[i].getPuesto()-j[i].getAvance());
                            int index=i+1;
                                 if (index<j.length) {
                                     
                                    j[i].setTurno(false);
                                    j[index].setTurno(true);
                                    frame.getTurno().setText(j[index].getNombre());
                                }else{
                                    j[i].setTurno(false);
                                    j[0].setTurno(true);
                                    //
                                    frame.getTurno().setText(j[0].getNombre());
                                }

                                 break;
                        }
                    }
                frame.setVisible(true);
                frame.settearfoco();
                JOptionPane.showMessageDialog(null, "...:::RESPUESTA INCORRECTA:::...");
            }
        }else
            if(b.isSelected()){
                if(b.getText().equals(respuesta)){
                    Jugador j[]=frame.getJugador();
                        for(int i=0;i<j.length;i++){
                            if(j[i].isTurno()){
                                j[i].setPuntaje(j[i].getPuntaje()+1);
                                if(j.length==4){
                                    if(i==0)
                                        frame.getJp1().setText(String.valueOf(j[i].getPuntaje()));
                                    else
                                        if(i==1)
                                            frame.getJp2().setText(String.valueOf(j[i].getPuntaje()));
                                        else
                                            if(i==2)
                                                frame.getJp3().setText(String.valueOf(j[i].getPuntaje()));
                                            else
                                                if(i==3)
                                                    frame.getJp4().setText(String.valueOf(j[i].getPuntaje()));
                                }else
                                    if(j.length==3){
                                        if(i==0)
                                            frame.getJp1().setText(String.valueOf(j[i].getPuntaje()));
                                        else
                                            if(i==1)
                                                frame.getJp2().setText(String.valueOf(j[i].getPuntaje()));
                                            else
                                                if(i==2)
                                                    frame.getJp3().setText(String.valueOf(j[i].getPuntaje()));
                                    }else
                                        if(j.length==2){
                                            if(i==0)
                                                frame.getJp1().setText(String.valueOf(j[i].getPuntaje()));
                                            else
                                                if(i==1)
                                                    frame.getJp2().setText(String.valueOf(j[i].getPuntaje()));
                                        }else
                                            if(j.length==1){
                                                if(i==0)
                                                    frame.getJp1().setText(String.valueOf(j[i].getPuntaje()));

                                            }
                            }
                        }
                        frame.setVisible(true);JOptionPane.showMessageDialog(null, "...:::RESPUESTA CORRECTA:::...");
                    }else{
                        Jugador j[]=frame.getJugador();
                            for(int i=0;i<j.length;i++){
                                if(j[i].isTurno()){
                                    j[i].setPuesto(j[i].getPuesto()-j[i].getAvance());
                                    int index=i+1;
                                         if (index<j.length) {
                                            j[index].setTurno(true);
                                            j[i].setTurno(false);
                                            frame.getTurno().setText(j[index].getNombre());
                                        }else{
                                            j[i].setTurno(false);
                                            j[0].setTurno(true);
                                            frame.getTurno().setText(j[0].getNombre());
                                        }

                                         break;
                                }
                            }
                        frame.setVisible(true);JOptionPane.showMessageDialog(null, "...:::RESPUESTA INCORRECTA:::...");
                    }
             
            }else
                if(c.isSelected()){
                    if(c.getText().equals(respuesta)){
                            Jugador j[]=frame.getJugador();
                            for(int i=0;i<j.length;i++){
                                if(j[i].isTurno()){
                                    j[i].setPuntaje(j[i].getPuntaje()+1);
                                    if(j.length==4){
                                        if(i==0)
                                            frame.getJp1().setText(String.valueOf(j[i].getPuntaje()));
                                        else
                                            if(i==1)
                                                frame.getJp2().setText(String.valueOf(j[i].getPuntaje()));
                                            else
                                                if(i==2)
                                                    frame.getJp3().setText(String.valueOf(j[i].getPuntaje()));
                                                else
                                                    if(i==3)
                                                        frame.getJp4().setText(String.valueOf(j[i].getPuntaje()));
                                    }else
                                        if(j.length==3){
                                            if(i==0)
                                                frame.getJp1().setText(String.valueOf(j[i].getPuntaje()));
                                            else
                                                if(i==1)
                                                    frame.getJp2().setText(String.valueOf(j[i].getPuntaje()));
                                                else
                                                    if(i==2)
                                                        frame.getJp3().setText(String.valueOf(j[i].getPuntaje()));
                                        }else
                                            if(j.length==2){
                                                if(i==0)
                                                    frame.getJp1().setText(String.valueOf(j[i].getPuntaje()));
                                                else
                                                    if(i==1)
                                                        frame.getJp2().setText(String.valueOf(j[i].getPuntaje()));
                                            }else
                                                if(j.length==1){
                                                    if(i==0)
                                                        frame.getJp1().setText(String.valueOf(j[i].getPuntaje()));

                                                }
                                }
                            }
                            frame.setVisible(true);JOptionPane.showMessageDialog(null, "...:::RESPUESTA CORRECTA:::...");
                        }else{
                            Jugador j[]=frame.getJugador();
                                for(int i=0;i<j.length;i++){
                                    if(j[i].isTurno()){
                                        j[i].setPuesto(j[i].getPuesto()-j[i].getAvance());
                                        int index=i+1;
                                             if (index<j.length) {
                                                j[index].setTurno(true);
                                                j[i].setTurno(false);
                                                frame.getTurno().setText(j[index].getNombre());
                                            }else{
                                                j[i].setTurno(false);
                                                j[0].setTurno(true);
                                                frame.getTurno().setText(j[0].getNombre());
                                            }

                                             break;
                                    }
                                }
                            frame.setVisible(true);JOptionPane.showMessageDialog(null, "...:::RESPUESTA INCORRECTA:::...");
                    }
                }else
                    if(d.isSelected()){
                        if(d.getText().equals(respuesta)){
                            Jugador j[]=frame.getJugador();
                        for(int i=0;i<j.length;i++){
                            if(j[i].isTurno()){
                                j[i].setPuntaje(j[i].getPuntaje()+1);
                                if(j.length==4){
                                    if(i==0)
                                        frame.getJp1().setText(String.valueOf(j[i].getPuntaje()));
                                    else
                                        if(i==1)
                                            frame.getJp2().setText(String.valueOf(j[i].getPuntaje()));
                                        else
                                            if(i==2)
                                                frame.getJp3().setText(String.valueOf(j[i].getPuntaje()));
                                            else
                                                if(i==3)
                                                    frame.getJp4().setText(String.valueOf(j[i].getPuntaje()));
                                }else
                                    if(j.length==3){
                                        if(i==0)
                                            frame.getJp1().setText(String.valueOf(j[i].getPuntaje()));
                                        else
                                            if(i==1)
                                                frame.getJp2().setText(String.valueOf(j[i].getPuntaje()));
                                            else
                                                if(i==2)
                                                    frame.getJp3().setText(String.valueOf(j[i].getPuntaje()));
                                    }else
                                        if(j.length==2){
                                            if(i==0)
                                                frame.getJp1().setText(String.valueOf(j[i].getPuntaje()));
                                            else
                                                if(i==1)
                                                    frame.getJp2().setText(String.valueOf(j[i].getPuntaje()));
                                        }else
                                            if(j.length==1){
                                                if(i==0)
                                                    frame.getJp1().setText(String.valueOf(j[i].getPuntaje()));

                                            }
                            }
                        }
                        frame.setVisible(true);JOptionPane.showMessageDialog(null, "...:::RESPUESTA CORRECTA:::...");
                    }else{
                        Jugador j[]=frame.getJugador();
                            for(int i=0;i<j.length;i++){
                                if(j[i].isTurno()){
                                    j[i].setPuesto(j[i].getPuesto()-j[i].getAvance());
                                    int index=i+1;
                                         if (index<j.length) {
                                            j[index].setTurno(true);
                                            j[i].setTurno(false);
                                            frame.getTurno().setText(j[index].getNombre());
                                        }else{
                                            j[i].setTurno(false);
                                            j[0].setTurno(true);
                                            frame.getTurno().setText(j[0].getNombre());
                                        }

                                         break;
                                }
                            }
                        frame.setVisible(true);JOptionPane.showMessageDialog(null, "...:::RESPUESTA INCORRECTA:::...");
                        }
                    }
        frame.setSW(true);
        System.out.println("sw1 "+frame.getSW());
    }

    private void iniciartemporizador() {
        t=new Timer(1000, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                
                segundero--;
                seg.setText(""+segundero);
                if(segundero==0){
                    t.stop();
                    Jugador j[]=frame.getJugador();
                            for(int i=0;i<j.length;i++){
                                if(j[i].isTurno()){
                                    j[i].setPuesto(j[i].getPuesto()-j[i].getAvance());
                                    int index=i+1;
                                         if (index<j.length) {
                                            j[index].setTurno(true);
                                            j[i].setTurno(false);
                                            frame.getTurno().setText(j[index].getNombre());
                                        }else{
                                            j[i].setTurno(false);
                                            j[0].setTurno(true);
                                            frame.getTurno().setText(j[0].getNombre());
                                        }

                                         break;
                                }
                            }
                         dispose();
                        frame.setVisible(true);
                        JOptionPane.showMessageDialog(null, "...:::TIEMPO AGOTADO:::...");
                        frame.setVisible(true);
                        frame.enable(true);
                        panel.setBorder(new MatteBorder(3, 3, 3, 3, new Color(255, 0, WIDTH)));
                        panel.setOpaque(false);
                        panel.setBackground(new Color(239, 239, 239));
                        JLabel label=(JLabel) panel.getComponent(0);
                        label.setForeground(Color.WHITE);
                        
                        t.stop();
                        frame.setSW(true);
                        System.out.println("sw"+frame.getSW());
                }
            }
        });
    }

}
